package com.nidu.demo.oauth2.executor.query;

import com.alibaba.cola.dto.PageResponse;
import com.nidu.demo.oauth2.convertor.OAuth2RefreshTokenCriteriaConvertor;
import com.nidu.demo.oauth2.dto.OAuth2RefreshTokenPageQry;
import com.nidu.demo.oauth2.convertor.OAuth2RefreshTokenConvertor;
import com.nidu.demo.oauth2.dto.OAuth2RefreshTokenCO;
import com.nidu.demo.oauth2.gateway.OAuth2RefreshTokenGateway;
import com.nidu.demo.oauth2.model.OAuth2RefreshToken;
import com.nidu.demo.oauth2.model.OAuth2RefreshTokenCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class OAuth2RefreshTokenPageQryExe {

    private final OAuth2RefreshTokenGateway gateway;

    private final OAuth2RefreshTokenConvertor convertor;

    private final OAuth2RefreshTokenCriteriaConvertor criteriaConvertor;

    public PageResponse<OAuth2RefreshTokenCO> execute(OAuth2RefreshTokenPageQry qry) {
        OAuth2RefreshTokenCriteria criteria = criteriaConvertor.toDataObject(qry);
        PageResponse<OAuth2RefreshToken> page = gateway.pageByCondition(criteria);
        List<OAuth2RefreshTokenCO> refreshTokenCOS = convertor.toClientObjects(page.getData());
        return PageResponse.of(refreshTokenCOS, page.getTotalCount(), page.getPageSize(), page.getPageIndex());
    }
    
}
